home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 41.zip
/
BS1 part 41
/
Lattice C v5.02 d4.adf
/
examples
/
cat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-11-07
|
598b
|
33 lines
/* (This program is from p. 154 of the Kernighan and Ritchie text */
#include <stdio.h>
main(argc, argv) /* cat: concatenate files */
int argc;
char *argv[];
{
FILE *fp, *fopen();
if (argc == 1) /* no args; copy standard input */
filecopy(stdin);
else
while (--argc > 0)
if ((fp = fopen(*++argv, "r")) == NULL) {
fprintf(stderr,
"cat: can't open %s\n", *argv);
exit(1);
} else {
filecopy(fp);
fclose(fp);
}
exit(0);
}
filecopy(fp) /* copy file fp to standard output */
FILE *fp;
{
int c;
while ((c = getc(fp)) != EOF)
putc(c, stdout);
}